package top.chmin.project.cloud.common.dict.data.auto;

// field import auto

import cn.hutool.core.bean.BeanUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.chmin.project.cloud.common.entity.Page;


/**
 * chmin
 * 2023-12-27 15:50:18
 * cloud-builder
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DictDataService {

    @Resource
    DictDataPlugin plugin;

    @Resource
    DictDataDao dictDataDao;

// field labelDao auto

    public int save(DictDataSave.Param param) {
        plugin.checkSave(param);
        DictData dictData = BeanUtil.toBean(param, DictData.class);
        plugin.beforeSave(dictData);
        int result = dictDataDao.save(dictData);
        plugin.afterSave(param, dictData, result);
        return result;
    }

    public int updateById(DictDataUpdateById.Param param) {
        plugin.checkUpdateById(param);
        DictData dictData = BeanUtil.toBean(param, DictData.class);
        plugin.beforeUpdateById(dictData);
        int result = dictDataDao.updateById(dictData);
        plugin.afterUpdateById(param, dictData, result);
        return result;
    }

    public int deleteById(DictDataDeleteById.Param param) {
        plugin.checkDeleteById(param);
        int result = dictDataDao.deleteById(param.getId());
        plugin.afterDeleteById(param, result);
        return result;
    }

    public DictDataSelectById.Result selectById(DictDataSelectById.Param param) {
        plugin.checkSelectById(param);
        DictDataFPC fpc = new DictDataFPC().id().eq(param.getId());
        plugin.beforeSelectById(param, fpc);
        DictDataSelectById.Result result = dictDataDao.getFirst(fpc.toCondition(), DictDataSelectById.Result.class);
        plugin.afterSelectById(param, result);
        return result;
    }

    public Page<DictDataSelectPage.Result> selectPage(DictDataSelectPage.Param param) {
        plugin.checkSelectPage(param);
        DictDataFPC fpc = new DictDataFPC();
        fpc = param.isDesc() ? fpc.id().desc() : fpc.id().asc();
        plugin.beforeSelectPage(param, fpc);
        Page<DictDataSelectPage.Result> result = dictDataDao.getPageByCondition(fpc.toCondition(), DictDataSelectPage.Result.class);
// field label auto
        plugin.afterSelectPage(param, result);
        return result;
    }

// entity select auto

// entity search auto

}
